<template>
  <div id="app">
    <header class="login-header">
      <el-button :plain="true" v-show="false">成功</el-button>
      <el-button :plain="true" v-show="false">错误</el-button>
      <div class="commonwidth">
        <h1 class="logo">
          <a href="#/">小兔鲜</a>
        </h1>
        <h3 class="sub">欢迎登录</h3>
        <a href="#/" class="entry">
          进入网站首页
          <i class="iconfont icon-angle-right"></i
          ><i class="iconfont icon-angle-right"></i
        ></a>
      </div>
    </header>
    <section class="login-section">
      <div class="wrapper">
        <nav>
          <a href="javascript:;">账户登录</a><a href="javascript:;">扫码登录</a>
        </nav>
        <div class="account-box">
          <div class="toggle">
            <a href="javascript:;"
              ><i class="iconfont icon-envelope-o"></i>
              使用短信登录
            </a>
          </div>
          <form novalidate="novalidate" autocomplete="off" class="form">
            <div class="form-item">
              <div class="input">
                <i class="iconfont icon-user-o"></i
                ><input
                  type="text"
                  placeholder="请输入用户名"
                  name="account"
                  v-model="usname"
                />
              </div>
              <!---->
            </div>
            <div class="form-item">
              <div class="input">
                <i class="iconfont icon-lock8"></i
                ><input
                  type="password"
                  placeholder="请输入密码"
                  name="password"
                  v-model="password"
                />
              </div>
              <!---->
            </div>
            <div class="form-item">
              <div class="agree">
                <!-- <div
                     
                    name="isAgree"
                    value="true"
                    class="xtx-checkbox"
                  >
                    <i
                       
                      class="iconfont icon-checkbox-unchecked"
                    ></i>
                  </div> -->
                <span>我已同意</span><a href="javascript:;">《隐私条款》</a
                ><span>和</span><a href="javascript:;">《服务条款》</a>
              </div>
            </div>
            <a href="javascript:;" class="btn" @click="login">登录</a>
          </form>
          <div class="action">
            <a
              href="https://graph.qq.com/oauth2.0/authorize?client_id=101941968&amp;response_type=token&amp;scope=all&amp;redirect_uri=http%3A%2F%2Ferabbit.itheima.net%2F%23%2Flogin%2Fcallback"
              ><img
                src="https://qzonestyle.gtimg.cn/qzone/vas/opensns/res/img/Connect_logo_7.png"
                alt=""
            /></a>
            <div class="url">
              <a href="javascript:;">忘记密码</a
              ><a href="javascript:;">免费注册</a>
            </div>
          </div>
        </div>
      </div>
    </section>
    <footer class="login-footer">
      <div class="commonwidth">
        <p>
          <a href="javascript:;">关于我们</a><a href="javascript:;">帮助中心</a
          ><a href="javascript:;">售后服务</a
          ><a href="javascript:;">配送与验收</a
          ><a href="javascript:;">商务合作</a><a href="javascript:;">搜索推荐</a
          ><a href="javascript:;">友情链接</a>
        </p>
        <p>CopyRight © 小兔鲜儿</p>
      </div>
    </footer>
    <!---->
  </div>
</template>
  <script>
import axios from "axios";
export default {
  data() {
    return {
      usname: "",
      password: "",
    };
  },
  methods: {
    login() {
      //调接口并登录
      //输入验证 通过之后
      var _this = this;
      axios({
        url: "http://pcapi-xiaotuxian-front-devtest.itheima.net/login",
        method: "post",
        data: {
          account: this.usname,
          password: this.password,
        },
        //请求成功后的返回值 登录成功
      })
        .then((res) => {
          console.log(res.data.result);
          
          if (res.data.msg == "操作成功") {
            // alert('登录成功')
            _this.$message({
              message: "登录成功",
              type: "success",
            },1000);
            _this.$router.push({ path: "/home" });
            this.$store.commit('settoken',res.data.result.token)
            this.$store.commit('setsccount',res.data.result.account)
          }
        })
        .catch(function (error) {
          //error 捕获错误 axios 发生错误的时候 执行的
          //用户不存在 密码无效
          // console.log(error);
          // alert(error.response.data.message)
          _this.$message.error(error.response.data.message);
        });
    },
  },
};
</script>
  <style scoped>
.login-header {
  background: #fff;
  border-bottom: 1px solid #e4e4e4;
}
.login-header .commonwidth {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
}
.login-header .logo {
  width: 200px;
}
.login-header .logo a {
  display: block;
  height: 132px;
  width: 100%;
  text-indent: -9999px;
  background: url("http://erabbit.itheima.net/img/logo.0940ebb5.png") no-repeat
    center 18px / contain;
}
.login-header .sub {
  flex: 1;
  font-size: 24px;
  font-weight: 400;
  margin-bottom: 38px;
  margin-left: 20px;
  color: #666;
}
.login-header .entry {
  width: 120px;
  margin-bottom: 38px;
  font-size: 16px;
}
.login-header .entry i {
  font-size: 14px;
  color: #27ba9b;
  letter-spacing: -5px;
}
.login-section {
  background: url("http://erabbit.itheima.net/img/login-bg.696efec3.png")
    no-repeat 50% / cover;
  height: 488px;
  position: relative;
}
.login-section .wrapper {
  width: 380px;
  background: #fff;
  min-height: 400px;
  position: absolute;
  left: 50%;
  top: 54px;
  transform: translate3d(100px, 0, 0);
  box-shadow: 0 0 10px rgb(0 0 0 / 15%);
}
.login-section .wrapper nav {
  height: 55px;
  border-bottom: 1px solid #f5f5f5;
  display: flex;
  padding: 0 40px;
  text-align: right;
  align-items: center;
}
.login-section .wrapper nav a :first-child {
  border-right: 1px solid #f5f5f5;
  text-align: left;
}
.login-section .wrapper nav a {
  flex: 1;
  line-height: 1;
  display: inline-block;
  font-size: 18px;
  position: relative;
}
.account-box .toggle {
  padding: 15px 40px;
  text-align: right;
}
.account-box .toggle a {
  color: #27ba9b;
}
.account-box .toggle a i {
  font-size: 14px;
}
.account-box .form {
  padding: 0 40px;
}
.account-box .form-item {
  margin-bottom: 28px;
}
.account-box .form-item .input {
  position: relative;
  height: 36px;
}
.account-box .form-item .input > i {
  width: 34px;
  height: 34px;
  background: #cfcdcd;
  color: #fff;
  position: absolute;
  left: 1px;
  top: 1px;
  text-align: center;
  line-height: 34px;
  font-size: 18px;
}
.account-box .form-item .input input {
  padding-left: 44px;
  border: 1px solid #cfcdcd;
  height: 36px;
  line-height: 36px;
  width: 80%;
}
.account-box .form-item {
  margin-bottom: 28px;
}
.account-box .form-item .input > i {
  width: 34px;
  height: 34px;
  background: #cfcdcd;
  color: #fff;
  position: absolute;
  left: 1px;
  top: 1px;
  text-align: center;
  line-height: 34px;
  font-size: 18px;
}
.account-box .form .btn {
  display: block;
  width: 100%;
  height: 40px;
  color: #fff !important;
  text-align: center;
  line-height: 40px;
  background: #27ba9b;

}
.account-box .action {
  padding: 20px 40px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.account-box .action .url a {
  color: #999;
  margin-left: 10px;
}
.login-footer {
  padding: 30px 0 50px;
  background: #fff;
}
.login-footer p {
  text-align: center;
  color: #999;
  padding-top: 20px;
}
.login-footer p a {
  line-height: 1;
  padding: 0 10px;
  color: #999;
  display: inline-block;
}
a{
  color: #333 !important;
}
</style>